package com.heima.search.service.impl;

import com.heima.common.dto.ResponseResult;
import com.heima.search.dto.ApArticleSearchDto;
import com.heima.search.entity.ApAssociateWords;
import com.heima.search.repository.AssociateWordsRepository;
import com.heima.search.service.IAssociateWordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssociateWordsServiceImpl implements IAssociateWordsService {

    @Autowired
    private AssociateWordsRepository repository;

    @Override
    public ResponseResult<List<ApAssociateWords>> search(ApArticleSearchDto dto) {
        // 根据用户输入的关键字,自动补全后面的联想词
        // 显示前面的10条数据
        // 按照创建时间倒序排列
        // List<ApAssociateWords> list = repository.findByAssociateWordsStartingWith(dto.getSearchWords());
        /*List<ApAssociateWords> list = repository.findTop10ByAssociateWordsStartingWithOrderByCreatedTimeDesc(dto.getSearchWords());
        return ResponseResult.okResult(list);*/

       // List<ApAssociateWords> byAssociateWordsStartingWith = repository.findByAssociateWordsStartingWith(dto.getSearchWords());

        List<ApAssociateWords> byAssociateWordsStartingWith = repository.findTop5ByAssociateWordsStartingWithOrderByCreatedTimeDesc(dto.getSearchWords());

        return ResponseResult.okResult(byAssociateWordsStartingWith);
    }
}
